package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.YzLiwu;
import com.ruoyi.system.service.IYzLiwuService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 礼物信息Controller
 *
 * @author linpq
 * @date 2020-04-10
 */
@Controller
@RequestMapping("/system/liwuInfo")
public class YzLiwuController extends BaseController
{
    private String prefix = "system/liwuInfo";

    @Autowired
    private IYzLiwuService yzLiwuService;

    @RequiresPermissions("system:liwuInfo:view")
    @GetMapping()
    public String liwuInfo()
    {
        return prefix + "/liwuInfo";
    }

    /**
     * 查询礼物信息列表
     */
    @RequiresPermissions("system:liwuInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YzLiwu yzLiwu)
    {
        startPage();
        List<YzLiwu> list = yzLiwuService.selectYzLiwuList(yzLiwu);
        return getDataTable(list);
    }

    /**
     * 导出礼物信息列表
     */
    @RequiresPermissions("system:liwuInfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YzLiwu yzLiwu)
    {
        List<YzLiwu> list = yzLiwuService.selectYzLiwuList(yzLiwu);
        ExcelUtil<YzLiwu> util = new ExcelUtil<YzLiwu>(YzLiwu.class);
        return util.exportExcel(list, "liwuInfo");
    }

    /**
     * 新增礼物信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存礼物信息
     */
    @RequiresPermissions("system:liwuInfo:add")
    @Log(title = "礼物信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YzLiwu yzLiwu)
    {


        return toAjax(yzLiwuService.insertYzLiwu(yzLiwu));
    }

    /**
     * 修改礼物信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        YzLiwu yzLiwu = yzLiwuService.selectYzLiwuById(id);
        mmap.put("yzLiwu", yzLiwu);
        return prefix + "/edit";
    }

    /**
     * 修改保存礼物信息
     */
    @RequiresPermissions("system:liwuInfo:edit")
    @Log(title = "礼物信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YzLiwu yzLiwu)
    {
        return toAjax(yzLiwuService.updateYzLiwu(yzLiwu));
    }

    /**
     * 删除礼物信息
     */
    @RequiresPermissions("system:liwuInfo:remove")
    @Log(title = "礼物信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(yzLiwuService.deleteYzLiwuByIds(ids));
    }
}
